﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 属性
{
    class Program
    {
        static void Main(string[] args)
        {
            student stu = new student();
            stu.Name= "张三";
            try
            {
                stu.Age = 21;
                stu.Age = -21;
            }
            catch (Exception)   
            {
                Console.WriteLine("年龄不能超过范围");
                
            }
            Console.WriteLine(stu);
            Console.ReadKey();
          
        }
    }
    class student
    {
        private string name;
        private int age;

        public string Name {
            get{ return name; }
            set { name = value; }
        }

        public int Age
        {
            get { return age; }
            set
            {
                if (value <= 1 | value > 100)
                    throw new ArgumentException("参数异常");
                age = value;
            }
        }

        public override string ToString()
        {
            return String.Format("{0}:{1}", name, age);
        }
    }

    
}
